package com.fary.web.multipart;

import com.fary.core.io.InputStreamSource;
import com.fary.core.io.Resource;
import com.fary.util.FileCopyUtils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;

public interface MultipartFile extends InputStreamSource {

	String getName();

	String getOriginalFilename();

	String getContentType();

	boolean isEmpty();

	long getSize();

	byte[] getBytes() throws IOException;

	@Override
	InputStream getInputStream() throws IOException;

	default Resource getResource() {
		return new MultipartFileResource(this);
	}

	void transferTo(File dest) throws IOException, IllegalStateException;

	default void transferTo(Path dest) throws IOException, IllegalStateException {
		FileCopyUtils.copy(getInputStream(), Files.newOutputStream(dest));
	}

}